package megadrum.util;

import java.util.Date;
import java.util.Vector;

public class Log {

    private Vector<String> date;
    private Vector<String> message;
    private Vector<String> type;

    public Log() {
        date = new Vector<String>();
        message = new Vector<String>();
        type = new Vector<String>();
    }

    public void info(String m) {
        date.add((new Date()).toString().substring(11, 19));
        message.add(m);
        type.add(INFO);
    }

    public void warn(String m) {
        date.add((new Date()).toString().substring(11, 19));
        message.add(m);
        type.add(WARNING);
    }

    public void error(String m) {
        date.add((new Date()).toString().substring(11, 19));
        message.add(m);
        type.add(ERROR);
    }

    public static String getExceptionInfo(Exception e){
        return e.getClass().toString() + " " + e.getMessage();
    }

    @Override
    public String toString() {
        return toString(true, true, true);
    }

    public String toString(boolean info, boolean warning, boolean error) {
        String texto = "";
        for (int i = 0; i < date.size(); i++) {
            String tip = type.get(i);
            if ((info && tip.equals(INFO)) ||
                    (warning && tip.equals(WARNING)) ||
                    (error && tip.equals(ERROR))) {
                texto = texto + "<font color=#ffffdd>" + date.get(i) + "</font>  <font color=#" + tip + ": " + message.get(i) + "</font><br>";
            }
        }
        return texto;
    }

    public void clean() {
        date.removeAllElements();
        message.removeAllElements();
        type.removeAllElements();
    }
    public final String INFO = "A4EDFF>INFO";
    public final String WARNING = "EFCB52>WARNING";
    public final String ERROR = "FA8585>ERROR";
}
